// https://umijs.org/config/
import { defineConfig } from 'umi';

import defaultSettings from './defaultSettings';
import proxy from './proxy';
import routes from './routes';
import theme from './theme';

const { UMI_ENV } = process.env;

const SERVER: any = {
  // uat: 'http://172.20.52.110/coupon-admin-api',
  // prod: 'http://coupon-admin.prd.yumc.local',
  // 生产环境: coupon-admin.hwwt2.com
  // 测试环境:coupon-admin-sit.hwwt2.com
  // Pre环境: coupon-admin-pre.hwwt2.com
  dev: 'http://172.20.52.110/coupon-admin-api',
  uat: 'http://172.20.52.110/coupon-admin-api',
  sit: 'http://coupon-admin-sit.hwwt2.com',
  pre: 'http://coupon-admin-pre.hwwt2.com',
  prod: 'http://coupon-admin.hwwt2.com/coupon-admin-api',
};

export default defineConfig({
  hash: true,
  // hash路由
  history: {
    type: 'hash',
  },
  antd: {},
  dva: {
    hmr: true,
  },
  layout: {
    // https://umijs.org/zh-CN/plugins/plugin-layout
    locale: false,
    siderWidth: 208,
    ...defaultSettings,
  },
  // https://umijs.org/zh-CN/plugins/plugin-locale
  locale: {
    // default zh-CN
    default: 'zh-CN',
    antd: true,
    // default true, when it is true, will use `navigator.language` overwrite default
    baseNavigator: true,
  },
  dynamicImport: {
    loading: '@ant-design/pro-layout/es/PageLoading',
  },
  targets: {
    ie: 11,
  },
  // umi routes: https://umijs.org/docs/routing
  routes,
  access: {},
  // Theme for antd: https://ant.design/docs/react/customize-theme-cn
  theme: {
    // 如果不想要 configProvide 动态设置主题需要把这个设置为 default
    // 只有设置为 variable， 才能使用 configProvide 动态设置主色调
    // https://ant.design/docs/react/customize-theme-variable-cn
    'root-entry-name': 'default',
    ...theme,
  },
  // esbuild is father build tools
  // https://umijs.org/plugins/plugin-esbuild
  esbuild: {},
  title: false,
  ignoreMomentLocale: true,
  proxy: proxy[UMI_ENV || 'dev'],
  manifest: {
    basePath: '/',
  },
  // Fast Refresh 热更新
  fastRefresh: {},
  openAPI: [
    // {
    //   requestLibPath: "import { request } from 'umi'",
    //   // 或者使用在线的版本
    //   // schemaPath: "https://gw.alipayobjects.com/os/antfincdn/M%24jrzTTYJN/oneapi.json"
    //   schemaPath: join(__dirname, 'oneapi.json'),
    //   mock: false,
    // },
    // {
    //   requestLibPath: "import { request } from 'umi'",
    //   schemaPath: 'https://gw.alipayobjects.com/os/antfincdn/CA1dOm%2631B/openapi.json',
    //   projectName: 'swagger',
    // },
  ],
  nodeModulesTransform: { type: 'none' },
  mfsu: {},
  webpack5: {},
  exportStatic: {},
  define: {
    API_CONFIGS: {
      server: SERVER[UMI_ENV || 'prod'],
      prefix: '/coupon-config',
    },
  },
  devServer: {
    port: 10086,
  },
});
